package likou.offer;

import java.util.ArrayList;
import java.util.Deque;
import java.util.LinkedList;
import java.util.List;

/**
 * @Info:
 * @Author: 唐小尊
 * @Date: 2020/8/16  9:46
 */
public class _31 {
    public static void main(String[] args) {
//        int pushed[] = {1, 2, 3, 4, 5};
//        int popped[] = {4, 3, 5, 1, 2};
//        System.out.println(validateStackSequences(pushed, popped));

        List<Integer> ww = new ArrayList<>();
        ww.add(1);
        Integer www [] = (Integer[]) ww.toArray();
        for (int x : ww){
            System.out.println(x);
        }



    }

    public static boolean validateStackSequences(int[] pushed, int[] popped) {
        int pushIndex = 0;
        int popIndex = 0;
        Deque<Integer> deque = new LinkedList<>();
        while (true) {
            while (pushIndex < pushed.length && pushed[pushIndex] != popped[popIndex]) {
                deque.push(pushed[pushIndex]);
                pushIndex++;
            }
            while (pushIndex < pushed.length && pushed[pushIndex] == popped[popIndex]) {
                pushIndex++;
                popIndex++;
            }
            while (deque.size() != 0 && deque.peek() == popped[popIndex]) {
                deque.pop();
                popIndex++;
            }
            if (pushIndex == pushed.length) {
                break;
            }
        }
        if (deque.size() != 0) {
            return false;
        } else {
            return true;
        }

    }
}
